#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int m,n;
openfile(char *filename);
closefile();
void main(int argc,char *argv[])
{
  
  char temp;
  char ch[8];
  int count1=0;
  int count2=0;
  openfile(argv[1]);
  while(read(m,&temp,1)!=0)
  {
    
    if(count1<7)
    {
      if(count1==0)
      printf("     ");
      printf("%4x ",temp);
      ch[count1]=temp;
      count1++;
      count2++;
    }
    else
    {
      printf("%4x ",temp);
      ch[count1]=temp;
      count1++;
      count2++;
      
      printf("\n");
      printf("%4d ",count2);
      for(int i=0;i<8;i++)
      {
        if(ch[i]=='\n')
        {
          printf("  \\n ");
        }
        else
        {
          printf("%4c ",ch[i]);
        }
      }
      printf("\n");
      count1=0;
    }
  }
  if(count1!=0)
  {
    printf("\n%4d ",count2);
    for(int i=0;i<count1;i++)
      {
        if(ch[i]=='\n')
        {
          printf("  \\n ");
        }
        else
        {
          printf("%4c ",ch[i]);
        }
      }
    printf("\n");
  }
  
  closefile();
}
openfile(char *filename)
{
  m=open(filename,O_RDONLY,0);
  if(m==-1)
  {
    printf("file open faild!\n");
  }
  /*else
  {
    printf("file open successful!\n");
  }*/
}
closefile()
{
  n=close(m);
  if(n==-1)
  {
    printf("file close faild!\n");
  }
  /*else
  {
    printf("file close successful!\n");
  }*/
}


